<template>
  <div class="app-container">
    <el-card shadow="never">

      <!-- 查询、筛选条件 -->
      <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-position="left" label-width="85px">
        <el-row :gutter="48">
          <el-col :xs="24" :sm="8">
            <el-form-item label="客户编码：" prop="code">
              <el-input v-model="queryParams.code" placeholder="请输入" clearable size="small" @keyup.enter.native="handleQuery" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="8">
            <el-form-item label="客户名称：" prop="name">
              <el-input v-model="queryParams.name" placeholder="请输入" clearable size="small" @keyup.enter.native="handleQuery" />
            </el-form-item>
          </el-col>
          <!-- 高级筛选 默认隐藏 -->
          <template v-if="advanced">
            <el-col :xs="24" :sm="8">
              <el-form-item label="法人：" prop="legalPerson">
                <el-input v-model="queryParams.legalPerson" placeholder="请输入" clearable size="small" @keyup.enter.native="handleQuery" />
              </el-form-item>
            </el-col>
          </template>
          <el-col :xs="24" :sm="!advanced && 8 || 24">
            <span class="search-advancedButton">
              <el-button v-waves type="primary" size="small" @click="handleQuery">查 询</el-button>
              <el-button size="small" @click="resetQuery">重 置</el-button>
              <el-button type="text" @click="advanced = !advanced">
                {{ advanced ? '收起' : '展开' }}
                <i :class="[!advanced && 'arrow-up' || 'arrow-down' ,'el-icon-arrow-up']" />
              </el-button>
            </span>
          </el-col>
        </el-row>
      </el-form>

      <el-row :gutter="10" class="mb16">
        <el-col :span="1.5">
          <el-button v-hasPermi="['customer:gh:add']" type="primary" icon="el-icon-plus" plain size="small" @click="handleAdd">新增</el-button>
        </el-col>
        <transition name="el-fade-in-linear">
          <el-col v-if="ids.length > 0" :span="1.5">
            <el-dropdown>
              <el-button size="small">
                批量操作<i class="el-icon-arrow-down el-icon--right" />
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="handleDelete">挑入私海</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </el-col>
        </transition>

        <!-- 工具栏 -->
        <right-toolbar :show-search.sync="showSearch" :show-download.sync="showDownload" @queryTable="getList">
          <template slot="download">
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item v-hasPermi="['customer:user:import']" icon="el-icon-upload2" @click.native="upload.show = true">导入</el-dropdown-item>
              <el-dropdown-item v-hasPermi="['customer:user:export']" divided icon="el-icon-download" @click.native="handleExport">导出</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="dataSource" @selection-change="handleSelectionChange">
        <template slot="empty">
          <el-empty />
        </template>
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column label="#" align="center" width="60">
          <template slot-scope="scope">
            <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户编码" prop="code" width="200" :show-overflow-tooltip="true" />
        <el-table-column label="公司名称" prop="name" width="300" :show-overflow-tooltip="true">
          <template slot-scope="{row}">
            <router-link :to="`/customer/details/${row.id}`" class="link-type">
              <span>{{ row.name }}</span>
            </router-link>
          </template>
        </el-table-column>
        <el-table-column label="法人" prop="legalPerson" />
        <el-table-column label="注册资金（万元）" prop="registeredCapital" />
        <el-table-column label="创建者" align="center" prop="createBy" />
        <el-table-column label="创建时间" align="center" prop="createTime">
          <template slot-scope="{row}">
            <span>{{ parseTime(row.createTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="{row}">
            <el-button v-hasPermi="['customer:gh:remove']" size="small" type="text" @click="handleAssign">指派</el-button>
            <el-divider direction="vertical" />
            <el-popconfirm confirm-button-text="确定" cancel-button-text="取消" icon="el-icon-info" icon-color="red" title="冻结操作不可撤销，是否确定?" @confirm="handleForzen(row.id)">
              <el-button slot="reference" v-hasPermi="['customer:gh:edit']" size="small" type="text">冻结</el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
    </el-card>

    <!-- 新增 -->
    <details-drawer ref="details" :show.sync="details.open" @close="getList" />
    <!-- 指派 -->
    <assgin-drawer :show.sync="assgin.open" @close="getList" />
    <!-- 导入 -->
    <zrk-upload :show.sync="upload.show" title="客户导入" :import-url="upload.importUrl" :template-url="upload.templateUrl" width="750" :accept="upload.accept" @getList="getList" />
  </div>
</template>

<script>
import DetailsDrawer from './modules/detailsDrawer'
import AssginDrawer from './modules/assginDrawer'
export default {
  name: 'GH',
  components: {
    AssginDrawer,
    DetailsDrawer
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      assgin: {
        open: false
      },
      details: {
        open: false
      },
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 显示下载工具
      showDownload: true,
      // 高级查询
      advanced: false,
      // 总条数
      total: 1,
      // 公告表格数据
      dataSource: [
        {
          code: 'KH2021050041',
          registeredCapital: '1000',
          legalPerson: '董亮',
          id: '1669840113571133737',
          createBy: '管理员',
          createTime: '2021-05-05',
          name: '青州市康达机械有限公司'
        },
        {
          code: 'KH2021050054',
          registeredCapital: '100',
          legalPerson: '王娟',
          id: '1389840113571188737',
          createBy: '管理员',
          createTime: '2021-05-05',
          name: '诸城市迈康机电科技有限公司'
        },
        {
          code: 'KH2021050051',
          registeredCapital: '30000',
          legalPerson: '丁俊洋',
          id: '1789840113571188867',
          createBy: '管理员',
          createTime: '2021-05-05',
          name: '山东省寿光蔬菜产业集团有限公司'
        }
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        noticeTitle: undefined,
        createBy: undefined,
        status: undefined
      },
      // 客户导入参数
      upload: {
        // 是否显示弹出层
        show: false,
        // 导入路径
        importUrl: '/customer/gh/importData',
        // 模板路径
        templateUrl: '/customer/gh/importTemplate',
        // 类型限制
        accept: '.xls,.xlsx'
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    getList() {},
    handleAdd() {
      this.details.open = true
      this.$refs.details.add()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id)
      this.multiple = !selection.length
    },
    // 挑入私海
    handleDelete() {
      this.$confirm('是否将选中的数据项挑入私海?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {})
        .then(() => {
          this.msgSuccess('挑入私海成功')
        })
    },
    // 指派
    handleAssign() {
      this.assgin.open = true
    },
    // 冻结
    handleForzen(id) {},
    // 查询
    handleQuery() {},
    // 重置查询条件
    resetQuery() {}
  }
}
</script>

<style lang='scss' scoped>
</style>
